package geektime.spring.hello.hellospring;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,
        DataSourceTransactionManagerAutoConfiguration.class,
        JdbcTemplateAutoConfiguration.class})
@Slf4j
public class HelloSpringApplication implements CommandLineRunner {

//	@Autowired(required = false)
//	private DataSource dataSource;

	public static void main(String[] args) {
		SpringApplication.run(HelloSpringApplication.class, args);
	}


	@RequestMapping("/hello")
	public String hello (){
		return "hello spring";
	}

	@Override
	public void run(String... args) throws Exception {
		log.info("~~~~~~~~~~run ");
		showConnection();
	}
	public void showConnection() throws SQLException {
//		log.info("dataSource:{}",dataSource.toString());
//		Connection connection = dataSource.getConnection();
//		log.info("connection:{}",connection.toString());
//		connection.close();
	}


	@Bean
	public CommandLineRunner lin1(){
		return (arg)->{
			System.out.println(123);
		};
	}
}
